package com.nstar.orderexpress.view
{
	import com.nstar.base.controls.AnimatedTileList;
	import com.nstar.base.util.EffectUtils;
	import com.nstar.orderexpress.control.OrderMenuThumbEvent;
	import com.nstar.orderexpress.model.Model;
	
	import mx.containers.Canvas;
	import mx.events.FlexEvent;
	
	public class SearchResultViewClass extends Canvas
	{
		public var atlResult:AnimatedTileList;
		
		private var model:Model = Model.getInstance();
		
		public function SearchResultViewClass()
		{
			//TODO: implement function
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			atlResult.addEventListener(OrderMenuThumbEvent.PURCHASE,orderMenuThumbEventHandler);
			atlResult.addEventListener(OrderMenuThumbEvent.ADD_FAVORITE,orderMenuThumbEventHandler);
		}
		
		//添加到购物车、收藏夹
		private function orderMenuThumbEventHandler(event:OrderMenuThumbEvent):void{
			switch (event.type){
				case OrderMenuThumbEvent.PURCHASE:
					model.mainApp.shoppingCartView.omlSelected.addOrderMenu(event.orderMenu);
					model.mainApp.shoppingCartView.dispatchEvent(event);
					break;
				case OrderMenuThumbEvent.ADD_FAVORITE:
					model.mainApp.favoriteView.omlFavorites.addOrderMenu(event.orderMenu);
					model.mainApp.favoriteView.dispatchEvent(event);
					break;
			}
			EffectUtils.moveAndDisppear(event.source, 20, 200);
			
		}

	}
}